package com.dl.study.module.base.roleinfo.controller;

import com.dl.study.base.PageResultDTO;
import com.dl.study.module.base.roleinfo.domain.dto.RoleInfoDTO;
import com.dl.study.module.base.roleinfo.domain.dto.RoleInfoQueryDTO;
import com.dl.study.module.base.roleinfo.domain.dto.RoleInfoListQueryDTO;
import com.dl.study.module.base.roleinfo.domain.vo.RoleInfoAddVO;
import com.dl.study.module.base.roleinfo.domain.vo.RoleInfoUpdateVO;
import com.dl.study.module.base.roleinfo.service.RoleInfoService;
import com.dl.study.util.BeanCopyUtil;
import com.dl.study.util.resp.ResponseDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * [ 角色信息表 ]
 *
 * @author dl
 * @version 1.0
 * @company xxxx
 * @copyright (c) 2019 xxxxInc. All rights reserved.
 * @date 2021-10-28 15:47:25
 * @since JDK1.8
 */
@RestController
@Api(tags = {"角色信息表" })
public class RoleInfoController {

    @Autowired
    private RoleInfoService roleInfoService;

    @ApiOperation(value = "分页查询角色信息表", notes = "@author dl")
    @PostMapping("/roleInfo/page/query")
    public ResponseDTO<PageResultDTO<RoleInfoDTO>> queryByPage(@RequestBody RoleInfoQueryDTO queryDTO) {
        return roleInfoService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "根据条件查询角色信息表", notes = "@author dl")
    @PostMapping("/roleInfo/list/query")
    public ResponseDTO<List<RoleInfoDTO>> queryListByCondition(@RequestBody RoleInfoListQueryDTO listQueryDTO) {
        return roleInfoService.queryListByCondition(listQueryDTO);
    }

    @ApiOperation(value = "添加角色信息表", notes = "@author dl")
    @PostMapping("/roleInfo/add")
    public ResponseDTO<String> add(@RequestBody @Valid RoleInfoAddVO addVO) {


        RoleInfoDTO dto = BeanCopyUtil.copy(addVO, RoleInfoDTO.class);
        return roleInfoService.add(dto);
    }

    @ApiOperation(value = "修改角色信息表", notes = "@author dl")
    @PostMapping("/roleInfo/update")
    public ResponseDTO<String> update(@RequestBody @Valid RoleInfoUpdateVO updateVO) {
        RoleInfoDTO dto = BeanCopyUtil.copy(updateVO, RoleInfoDTO.class);

        return roleInfoService.update(dto);
    }


    @ApiOperation(value = "删除角色信息表", notes = "@author dl")
    @GetMapping("/roleInfo/delete/{id}")
    public ResponseDTO<String> delete(@PathVariable("id") Long id) {
        return roleInfoService.delete(id);
    }


    @ApiOperation(value = "详情角色信息表", notes = "@author dl")
    @GetMapping("/roleInfo/detail/{id}")
    public ResponseDTO<RoleInfoDTO> detail(@PathVariable("id") Long id) {
        return roleInfoService.detail(id);
    }


    @ApiOperation(value = "批量删除角色信息表", notes = "@author dl")
    @PostMapping("/roleInfo/deleteByIds")
    public ResponseDTO<String> deleteByIds(@RequestBody @Valid List<Long> ids) {
        return roleInfoService.deleteByIds(ids);
    }


    @ApiOperation(value = "批量添加角色信息表", notes = "@author dl")
    @PostMapping("/roleInfo/addList")
    public ResponseDTO<String> addList(@RequestBody @Valid List<RoleInfoDTO> addList) {
        return roleInfoService.addList(addList);
    }
}
